package m1;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Producer {
    public static void main(String[] args) throws IOException, TimeoutException {
        // 连接
        ConnectionFactory f = new ConnectionFactory();
        f.setHost("192.168.64.140");  // "wht6.cn"
        f.setPort(5672);
        f.setUsername("admin");
        f.setPassword("admin");
        Connection con = f.newConnection();
        Channel c = con.createChannel(); //通信通道

        // 在服务器上创建队列 helloworld， helloworld-xf， helloworld-zx
        // 如果队列已经存在，不会重复创建
        c.queueDeclare("helloworld",false,false,false,null);

        // 向 helloworld 队列发送消息
        c.basicPublish("", "helloworld", null, "Hello world!".getBytes());
        System.out.println("消息已发送");
    }
}
